//
//  EditInfoViewController.m
//  jiyujiaProgram
//
//  Created by Jame on 15/12/2.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "InfoViewController.h"
#import "ExpModel.h"
#import "CommentModel.h"
#import "MineCommentCell.h"

#import "ExpViewController.h"
#import "EditInfoViewController.h"
#import "ScheduleViewController.h"

@interface InfoViewController () <UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIAlertViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

//@property (nonatomic, copy) NSString *imageId;
//@property (nonatomic, copy) NSString *imageUrl;

@end

@implementation InfoViewController
{
    UIScrollView *_scrollView;
    UIImageView *_userHeadImage;
    
    UIView *_signView;
    UIImageView *_headImage;
    UILabel *_nameLabel;
    UILabel *_signInfo;
    UIButton *_editButton;
    
    
    UIView *_baseInfoView;
    UILabel *_nameInfo;
    UILabel *_birthInfo;
    UILabel *_sexInfo;
    UILabel *_fromInfo;
    UILabel *_proInfo;
    UILabel *_collegeInfo;
    UILabel *_teachYearInfo;
    
    
    UIView *_teacherInfoView;
    UILabel *_specialClassInfo;
    UILabel *_edutimeInfo;
    UILabel *_eduexpInfo;
    
    
    UILabel *_totalLabel;
    UILabel *_sepcialWayInfo;
    UILabel *_classWayInfo;
    UIView *_commentView;
    UITableView *_tableView;
    UILabel *_totalNumLabel;
    
    
    MemberModel *_memberModel;
    TeacherModel *_teacherModel;
    NSMutableArray *_dataArray;
    BOOL isSelf;
    BOOL isStudent;
    
    UIActionSheet *_photoActionSheet;
    NSData *_imageData;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatNavigationBarWithImage:nil title:@"个人首页"];
    [self creatNavigationBarLeftItemWithLeftTitle:nil LeftImage:ECIMAGENAME(@"back_button.png")];
    [self creatNavigationBarRightItemWithRightTitle:nil RightImage:ECIMAGENAME(@"mine_photo.png")];
    self.navcImageView.alpha = 0;
    
    [self creatScrollView];
    [self creatTopView];
    [self creatSignView];
    [self creatBaseInfoView];
    [self creatTeacherInfoView];
    [self creatCommentView];
    
    [self.view bringSubviewToFront:self.navcImageView];
    [self.view bringSubviewToFront:self.leftImageView];
    [self.view bringSubviewToFront:self.leftButton];
    [self.view bringSubviewToFront:self.rightImageView];
    [self.view bringSubviewToFront:self.rightButton];
}


- (void)viewWillAppear:(BOOL)animated
{
    [self loadUserInfo];
    if ([_memberModel.member_Id isEqualToString:self.memberId]) {
        isSelf = YES;
        isStudent = NO;
        [_editButton setTitle:@"编辑个人资料" forState:UIControlStateNormal];
    }else{
        isSelf = NO;
        if ([_memberModel.member_type isEqualToString:@"2"]) {
            isStudent = YES;
            [_editButton setTitle:@"查询教师课表" forState:UIControlStateNormal];
        }else{
            isStudent = NO;
            _editButton.hidden = YES;
        }
    }
    [self creatFirstHttpRequest];
    [self creatSecondHttpRequest];
    [self creatThirdHttpRequest];
    [self creatFourthHttpRequest];
}


- (void)loadUserInfo
{
    UserInfoManager *userInfo = [UserInfoManager sharedUserInfoManager];
    [userInfo loadUserInfoFromSanbox];
    _memberModel = userInfo.memberModel;
    _teacherModel = userInfo.teacherModel;
}

- (void)leftBtnClick:(id)leftSender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)rightBtnClick:(id)rightSender
{
    if (isSelf) {
        _photoActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册", @"相机",nil];
        [_photoActionSheet showInView:self.view];
    }else{
        SHOW_ALERT(@"提示", @"您没有权限修改背景图片", @"好的", nil, nil);
    }
    
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet == _photoActionSheet){
        switch (buttonIndex)
        {
            case 0:
            {
                if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
                {
                    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                    picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
                    picker.delegate = self;
                    picker.allowsEditing = YES;
                    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    [self presentViewController:picker animated:YES completion:nil];
                }
            }
                break;
                
            case 1:
            {
                if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                {
                    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                    picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
                    picker.delegate = self;
                    picker.allowsEditing = YES;
                    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                    [self presentViewController:picker animated:YES completion:nil];
                }
            }
                break;
                
            default:
                break;
        }
    }
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
//    _userHeadImage.image = image;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    
    dispatch_async(queue, ^{
        
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
        {
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }
        
        if (UIImagePNGRepresentation(image))
        {
            UIImage *newImage = [ECHelper imageWithImageSimple:image scaledToSize:CGSizeMake(320.0f, 320.0f)];
            _imageData = UIImagePNGRepresentation(newImage);
        }
        else
        {
            UIImage *newImage = [ECHelper imageWithImageSimple:image scaledToSize:CGSizeMake(320.0f, 320.0f)];
            _imageData = UIImageJPEGRepresentation(newImage, 0.75);
        }
        
    });
    
#warning ******************POSTPIC********************
    [self dismissViewControllerAnimated:YES completion:^{
        
        NSString *strRandomName = [NSString stringWithFormat:@"iOS_uploadImage_%d.jpg",arc4random_uniform(10000)];
        
        NSArray *files = @[
                           @{
                               @"name": strRandomName,
                               @"file": _imageData ,
                               @"key": @"image",
                               @"type": @"multipart/form-data"
                               }
                           ];
        
        [[HttpManager defaultManager] uploadToUrl:RequestURL(POSTPIC) params:nil files:files complete:^(BOOL successed, NSDictionary *result) {
            if (successed) {
                if ([result[@"errCode"] integerValue] == 0) {
                    [[HttpManager defaultManager] postRequestToUrl:RequestURL(UPDATEMINE) params:@{@"member_Id":self.memberId,@"homepage_background_imgId":result[@"pictures_ID"],}complete:^(BOOL successed, NSDictionary *result) {
                        if (successed) {
                            [_userHeadImage sd_setImageWithURL:[NSURL URLWithString:result[@"homepage_background_imgUrl"]] placeholderImage:ECIMAGENAME(@"mine_top_bg.png")];
                            SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                        }
                    }];
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }];
}


- (void)creatFirstHttpRequest
{
    NSDictionary *param = @{
                            @"member_Id":self.memberId,
                            };
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(MINE) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            MemberModel *member = [[MemberModel alloc] init];
            member = [MemberModel objectWithKeyValues:result];
            
            if (isSelf) {
                UserInfoManager *userInfo = [UserInfoManager sharedUserInfoManager];
                userInfo.memberModel = member;
                [userInfo saveUserInfoToSanbox];
            }
            
            [self reloadSignViewWithModel:member];
            [self reloadBaseViewWithMModel:member];
        }
    }];
}


- (void)creatSecondHttpRequest
{
    NSDictionary *param = @{
                            @"member_Id":self.memberId,
                            };
    
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(MINEINFO) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            TeacherModel *teacher = [[TeacherModel alloc] init];
            teacher = [TeacherModel objectWithKeyValues:result];
            
            if (isSelf) {
                UserInfoManager *userInfo = [UserInfoManager sharedUserInfoManager];
                userInfo.teacherModel = teacher;
                [userInfo saveUserInfoToSanbox];
            }
            
            [self reloadBaseViewWithTModel:teacher];
            [self reloadTeacherViewWithModel:teacher];
        }
    }];
}


- (void)creatThirdHttpRequest
{
    NSDictionary *param = @{
                            @"teacher_Id":self.memberId,
                            };
    
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(EXPINFO) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            [ExpModel setupObjectClassInArray:^NSDictionary *{
                return @{
                         @"data":@"ExpData",
                         };
            }];
            
            ExpModel *exp = [[ExpModel alloc] init];
            exp = [ExpModel objectWithKeyValues:result];
            
            [self reloadTeacherViewWithEXPModel:exp];
        }
    }];

}


- (void)creatFourthHttpRequest
{
    NSDictionary *param = @{
                            @"t_member_id":self.memberId,
                            @"pageIndex":@"0",
                            @"pageSize":@"999",
                            };
    
    [[HttpManager defaultManager] postRequestToUrl:RequestURL(SCHEDULECOMMENT) params:param complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            [CommentModel setupObjectClassInArray:^NSDictionary *{
                return @{
                         @"data":@"CommentData",
                         };
            }];
            
            if (_dataArray) {
                [_dataArray removeAllObjects];
            }else{
                _dataArray = [[NSMutableArray alloc] init];
            }
            
            CommentModel *comment = [[CommentModel alloc] init];
            comment = [CommentModel objectWithKeyValues:result];
            [_dataArray addObjectsFromArray:comment.data];
            
            _totalLabel.text = [NSString stringWithFormat:@"共%@条评论",comment.total];
            
            [_tableView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(90*comment.data.count);
            }];
            
            [_commentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(40 + 90 *comment.data.count);
            }];
            _scrollView.contentSize = CGSizeMake(ECSCREEN_W, 740 + 90 *comment.data.count + 5);
            [_tableView reloadData];
            [self.view layoutIfNeeded];
        }
    }];
}

- (void)reloadSignViewWithModel:(MemberModel *)model
{
    _nameLabel.text = model.name;
    _signInfo.text = model.signature;
    [_headImage sd_setImageWithURL:[NSURL URLWithString:model.imgUrl] placeholderImage:ECIMAGENAME(@"header.png")];
}

- (void)reloadBaseViewWithMModel:(MemberModel *)model
{
    _nameInfo.text = model.name;
    _birthInfo.text = model.age;
    _fromInfo.text = model.city;
    _sexInfo.text = model.sex;
    _collegeInfo.text = model.school;
    [_userHeadImage sd_setImageWithURL:[NSURL URLWithString:model.homepage_background_imgUrl] placeholderImage:ECIMAGENAME(@"mine_top_bg.png")];
}

- (void)reloadBaseViewWithTModel:(TeacherModel *)model
{
    _proInfo.text = model.specialty;
    _teachYearInfo.text = model.seniority;
}

- (void)reloadTeacherViewWithModel:(TeacherModel *)model
{
    _specialClassInfo.text = model.special_programs;
    _sepcialWayInfo.text = model.teaching_skills;
    _classWayInfo.text = model.have_lessons_way;
}

- (void)reloadTeacherViewWithEXPModel:(ExpModel *)model
{
    if (model.data.count > 0) {
        ExpData *data = model.data[0];
        
        NSString *start = [self stringWithDate:[NSDate dateWithTimeIntervalSince1970:[[data startTime] integerValue]/1000]];
        NSString *end = [self stringWithDate:[NSDate dateWithTimeIntervalSince1970:[[data endTime] integerValue]/1000]];
        _edutimeInfo.text = [NSString stringWithFormat:@"%@-%@",start,end];
        _eduexpInfo.text = data.descr;
    }else{
        _edutimeInfo.text = @"";
        _eduexpInfo.text = @"";
    }
}


- (NSString *)stringWithDate:(NSDate *)date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

- (void)creatScrollView
{
    CGRect rect = [[UIApplication sharedApplication] statusBarFrame];

    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -rect.size.height, ECSCREEN_W, ECSCREEN_H + rect.size.height)];
    _scrollView.delegate = self;
    _scrollView.contentSize = CGSizeMake(ECSCREEN_W, 740);
    _scrollView.backgroundColor = BG_COLOR;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGRect rect = [[UIApplication sharedApplication] statusBarFrame];
    CGFloat yOffset   = scrollView.contentOffset.y;
    
    NSLog(@"****%f*****",yOffset);
    self.navcImageView.alpha = yOffset/(200 - 64 - rect.size.height);
    NSLog(@"%f",yOffset/(200 - 64 - rect.size.height));
}


- (void)creatTopView
{
    _userHeadImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 200)];
    _userHeadImage.image = ECIMAGENAME(@"mine_top_bg.png");
    [_scrollView addSubview:_userHeadImage];
    
}


- (void)creatSignView
{
    _signView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, ECSCREEN_W, 60)];
    _signView.backgroundColor = BG_COLOR ;
    [_scrollView addSubview:_signView];
    
    
    UIImageView *headBg = [[UIImageView alloc] initWithFrame:CGRectMake(20, -25, 50, 50)];
    headBg.backgroundColor = ECCOLOR(255, 255, 255, 1);
    headBg.clipsToBounds = YES;
    headBg.layer.cornerRadius = 1;
    [_signView addSubview:headBg];
    
    _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, 48, 48)];
    _headImage.image = ECIMAGENAME(@"header.png");
    _headImage.clipsToBounds = YES;
    _headImage.layer.cornerRadius = 1;
    [headBg addSubview:_headImage];
    
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, ECSCREEN_W - 80 -  100, 25)];
    _nameLabel.text = @"笑笑";
    _nameLabel.font = [UIFont systemFontOfSize:15.f];
    _nameLabel.textColor = NAVC_COLOR;
    [_signView addSubview:_nameLabel];
    
    
    UILabel *signTitle = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 50, 30)];
    signTitle.text = @"签名:";
    signTitle.font = [UIFont systemFontOfSize:15.f];
    [_signView addSubview:signTitle];
    
    
    _signInfo = [[UILabel alloc] initWithFrame:CGRectMake(70, 30, ECSCREEN_W - 80, 30)];
    _signInfo.text = @"做一个有情怀的老师！不仅仅可以教书，还是孩子们的知心朋友，可以倾诉的对象……";
    _signInfo.numberOfLines = 2;
    _signInfo.font = [UIFont systemFontOfSize:11.f];
    [_signView addSubview:_signInfo];
    
    
    _editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _editButton.frame = CGRectMake(ECSCREEN_W - 90, 3, 80, 24);
    _editButton.backgroundColor = NAVC_COLOR;
    [_editButton setTitle:@"编辑个人资料" forState:UIControlStateNormal];
    [_editButton setTitleColor:ECCOLOR(255, 255, 255, 1) forState:UIControlStateNormal];
    _editButton.clipsToBounds = YES;
    _editButton.layer.cornerRadius = 1;
    _editButton.titleLabel.font = [UIFont systemFontOfSize:11.f];
    [_editButton addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
    [_signView addSubview:_editButton];
}


- (void)editClick:(UIButton *)button
{
    if (isSelf) {
        EditInfoViewController *vc = [[EditInfoViewController alloc] init];
        vc.headUrl = _memberModel.imgUrl;
        vc.name = _nameInfo.text;
        vc.birthday = _birthInfo.text;
        vc.sex = _sexInfo.text;
        vc.from = _fromInfo.text;
        vc.pro = _proInfo.text;
        vc.college = _collegeInfo.text;
        vc.teachYear = _teachYearInfo.text;
        vc.specialClass = _specialClassInfo.text;
        vc.specialWay = _sepcialWayInfo.text;
        vc.classWay = _classWayInfo.text;
        vc.sign = _signInfo.text;
        vc.memberId = self.memberId;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        if (isStudent) {
            ScheduleViewController *vc = [[ScheduleViewController alloc] init];
            vc.isStudent = YES;
            vc.memberId = self.memberId;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}


- (void)creatBaseInfoView
{
    _baseInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 260, ECSCREEN_W, 220)];
    _baseInfoView.backgroundColor = BG_COLOR;
    [_scrollView addSubview:_baseInfoView];
    
    
    UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(10, 10, ECSCREEN_W - 20, 200)];
    bg.backgroundColor = ECCOLOR(255, 255, 255, 1);
    bg.clipsToBounds = YES;
    bg.layer.cornerRadius = 3;
    [_baseInfoView addSubview:bg];
    
    //title
    NSArray *titleArr = @[@"姓名:",@"年龄:",@"性别:",@"来自:",@"专业:",@"毕业院校:",@"教龄:"];
    for (int i = 0; i < titleArr.count; i ++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, i * 28 + 2, 75, 28)];
        titleLabel.text = titleArr[i];
        titleLabel.textAlignment = NSTextAlignmentRight;
        titleLabel.textColor = ECCOLOR(0, 0, 0, 1);
        titleLabel.font = [UIFont systemFontOfSize:13.f];
        [bg addSubview:titleLabel];
        
        if(i+1 < titleArr.count){
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, (i + 1)*28, ECSCREEN_W - 40, 1)];
            line.backgroundColor = ECCOLOR(0, 0, 0, .3f);
            [bg addSubview:line];
        }
    }
    
    
    _nameInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 2, ECSCREEN_W - 40 - 80, 28)];
    _nameInfo.text = @"笑笑";
    _nameInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_nameInfo];
    
    _birthInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 30, ECSCREEN_W - 40 - 80, 28)];
    _birthInfo.text = @"29";
    _birthInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_birthInfo];
    
    _sexInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 58, ECSCREEN_W - 40 - 80, 28)];
    _sexInfo.text = @"女";
    _sexInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_sexInfo];

    _fromInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 86, ECSCREEN_W - 40 - 80, 28)];
    _fromInfo.text = @"常州";
    _fromInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_fromInfo];

    _proInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 114, ECSCREEN_W - 40 - 80, 28)];
    _proInfo.text = @"日语";
    _proInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_proInfo];

    _collegeInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 142, ECSCREEN_W - 40 - 80, 28)];
    _collegeInfo.text = @"BTJ商务日语学院";
    _collegeInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_collegeInfo];
    
    
    _teachYearInfo = [[UILabel alloc] initWithFrame:CGRectMake(80, 170, ECSCREEN_W - 40 - 80, 28)];
    _teachYearInfo.text = @"5年";
    _teachYearInfo.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_teachYearInfo];
}


- (void)creatTeacherInfoView
{
    _teacherInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 260 +220, ECSCREEN_W, 220)];
    _teacherInfoView.backgroundColor = BG_COLOR;
    [_scrollView addSubview:_teacherInfoView];
    
    
    UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(10, 10, ECSCREEN_W - 20, 220)];
    bg.backgroundColor = ECCOLOR(255, 255, 255, 1);
    bg.clipsToBounds = YES;
    bg.layer.cornerRadius = 3;
    [_teacherInfoView addSubview:bg];
    
    
    
    //特色课程
    UIImageView *specialImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
    specialImage.image = ECIMAGENAME(@"special.png");
    [bg addSubview:specialImage];
    
    
    UILabel *specialTitle = [[UILabel alloc] initWithFrame:CGRectMake(35, 6, 60, 28)];
    specialTitle.text = @"特色课程:";
    specialTitle.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:specialTitle];
    
    
    _specialClassInfo = [[UILabel alloc] initWithFrame:CGRectMake(100, 6, ECSCREEN_W - 30 - 100, 28)];
    _specialClassInfo.text = @"超好笑英语";
    _specialClassInfo.font = [UIFont systemFontOfSize:13.f];
    _specialClassInfo.textColor = [UIColor lightGrayColor];
//    _specialInfo.backgroundColor = [UIColor redColor];
    [bg addSubview:_specialClassInfo];
    
    
    
    //教学经历
    UIImageView *eduexpImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 40, 20, 20)];
    eduexpImage.image = ECIMAGENAME(@"edu_exp.png");
    [bg addSubview:eduexpImage];
    
    
    UILabel *eduexpTitle = [[UILabel alloc] initWithFrame:CGRectMake(35, 36, 60, 28)];
    eduexpTitle.text = @"教学经历:";
    eduexpTitle.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:eduexpTitle];
    
    UIImageView *eduexpMore = [[UIImageView alloc] initWithFrame:CGRectMake(ECSCREEN_W - 40 - 10, 36, 20, 20)];
    eduexpMore.image = ECIMAGENAME(@"right_to_more.png");
    [bg addSubview:eduexpMore];
    
    _edutimeInfo = [[UILabel alloc] initWithFrame:CGRectMake(35, 60, ECSCREEN_W - 30 - 35, 15)];
    _edutimeInfo.textColor = NAVC_COLOR;
    _edutimeInfo.text = @"";
    _edutimeInfo.font = [UIFont systemFontOfSize:11.f];
//    _edutimeInfo.backgroundColor = [UIColor redColor];
    [bg addSubview:_edutimeInfo];
    
    _eduexpInfo = [[UILabel alloc] initWithFrame:CGRectMake(35, 75, ECSCREEN_W - 30 - 35, 30)];
//    _eduexpInfo.backgroundColor = [UIColor orangeColor];
    _eduexpInfo.numberOfLines = 2;
    _eduexpInfo.text = @"";
    _eduexpInfo.font = [UIFont systemFontOfSize:11.f];
    [bg addSubview:_eduexpInfo];
    
    
    UIButton *expButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    expButton.backgroundColor = [UIColor redColor];
    expButton.frame = CGRectMake(0, 36, ECSCREEN_W - 20, 70);
    [expButton addTarget:self action:@selector(expClick:) forControlEvents:UIControlEventTouchUpInside];
    [bg addSubview:expButton];
    
    UIView *firstLine = [[UIView alloc] initWithFrame:CGRectMake(10, 109, ECSCREEN_W - 40, 1)];
    firstLine.backgroundColor = ECCOLOR(0, 0, 0, .3f);
    [bg addSubview:firstLine];
    
    
    
    //特长
    UIImageView *eduspecialImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 120, 20, 20)];
    eduspecialImage.image = ECIMAGENAME(@"edu_special.png");
    [bg addSubview:eduspecialImage];

    
    UILabel *eduspecialTitle = [[UILabel alloc] initWithFrame:CGRectMake(35, 120, 60, 20)];
    eduspecialTitle.text = @"教学特长:";
    eduspecialTitle.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:eduspecialTitle];
    
    _sepcialWayInfo = [[UILabel alloc] initWithFrame:CGRectMake(95, 120, ECSCREEN_W - 40 - 95, 20)];
    _sepcialWayInfo.text = @"风情幽默、擅长口语、受学生喜欢、思路清晰";
    _sepcialWayInfo.font = [UIFont systemFontOfSize:11.f];
    [bg addSubview:_sepcialWayInfo];
    
    
    UIView *secondLine = [[UIView alloc] initWithFrame:CGRectMake(10, 149, ECSCREEN_W - 40, 1)];
    secondLine.backgroundColor = ECCOLOR(0, 0, 0, .3);
    [bg addSubview:secondLine];
    
    
    UIImageView *eduwayImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 160, 20, 20)];
    eduwayImage.image = ECIMAGENAME(@"edu_way.png");
    [bg addSubview:eduwayImage];
    
    
    UILabel *eduwayTitle = [[UILabel alloc] initWithFrame:CGRectMake(35, 160, 60, 20)];
    eduwayTitle.text = @"上课方式:";
    eduwayTitle.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:eduwayTitle];
    
    
    _classWayInfo = [[UILabel alloc] initWithFrame:CGRectMake(95, 160, ECSCREEN_W - 40 - 95, 20)];
    _classWayInfo.text = @"老师上门、学生上门、双方协商、在线授课";
    _classWayInfo.font = [UIFont systemFontOfSize:11.f];
    [bg addSubview:_classWayInfo];
    
    
    _totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 190, ECSCREEN_W - 40 - 35, 20)];
    _totalLabel.text = @"授课时长：1小时 | 人数：110 | 课时：120 | 好评率：100%";
    _totalLabel.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_totalLabel];
    
}


- (void)expClick:(UIButton *)button
{
    ExpViewController *vc = [[ExpViewController alloc] init];
    vc.isSelf = isSelf;
    vc.memberId = self.memberId;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)creatCommentView
{
    _commentView = [UIView new];
    _commentView.backgroundColor = BG_COLOR;
    [_scrollView addSubview:_commentView];
    
    [_commentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_teacherInfoView.mas_bottom).offset(0);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(ECSCREEN_W);
        make.height.mas_greaterThanOrEqualTo(40);
    }];
    
    
    UIView *bg = [UIView new];
    bg.backgroundColor = ECCOLOR(255, 255, 255, 1);
    [_commentView addSubview:bg];
    
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_commentView.mas_top).offset(0);
        make.width.mas_equalTo(ECSCREEN_W - 20);
        make.centerX.mas_equalTo(_commentView.mas_centerX);
        make.bottom.mas_equalTo(_commentView.mas_bottom).offset(0);
    }];
    
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 60, 40)];
    title.text = @"课程评价";
    title.font = [UIFont systemFontOfSize:15.f];
    [bg addSubview:title];
    
    
    
    _totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, ECSCREEN_W - 20 - 70, 40)];
    _totalLabel.text = @"共110条评价";
    _totalLabel.textColor = [UIColor lightGrayColor];
    _totalLabel.font = [UIFont systemFontOfSize:13.f];
    [bg addSubview:_totalLabel];
    
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(5, 39, ECSCREEN_W - 30, 1)];
    lineView.backgroundColor = ECCOLOR(0, 0, 0, .3);
    [bg addSubview:lineView];
    
    
    _tableView = [UITableView new];
    [bg addSubview:_tableView];
    
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bg.mas_top).offset(40);
        make.centerX.mas_equalTo(bg.mas_centerX);
        make.width.mas_equalTo(ECSCREEN_W - 20);
        make.height.mas_greaterThanOrEqualTo(0);
    }];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    _tableView.tableFooterView = [[UIView alloc]init];
    
    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90.f;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}


//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return _dataArray.count;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 5.f;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 5)];
//    view.backgroundColor = BG_COLOR;
//    return view;
//}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseIdentifier = @"mineCommentCell";
    MineCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (nil == cell) {
        NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"MineCommentCell" owner:nil options:nil];
        for (NSObject *obj in arr) {
            if ([obj isKindOfClass:[MineCommentCell class]]) {
                cell = (MineCommentCell *)obj;
                if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                    [cell setSeparatorInset:UIEdgeInsetsZero];
                }
                if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                    [cell setLayoutMargins:UIEdgeInsetsZero];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                break;
            }
        }
    }
    [cell setCellWithModel:_dataArray WithIndexPath:indexPath];
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
